package com.damai.mvc.view.imple;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.citywithincity.api.ApiConfig;
import com.citywithincity.utils.JsonUtil;
import com.damai.error.ApiError;
import com.damai.mvc.view.ErrorRender;


public class ApiErrorRender implements ErrorRender {
	
	public static final ApiErrorRender DEFAULT = new ApiErrorRender();
	
	@Override
	public void renderError(Throwable e, HttpServletRequest request, HttpServletResponse response) throws IOException {		
		if(e instanceof ApiError){
			((ApiError)e).render(response.getWriter());
		}else{
			ApiConfig.error("runtimeException", e);
			response.getWriter().print(JsonUtil.ERROR_SERVER_JSON);
		}
	}

}
